package com.shuzijun.leetcode.editor.cn;
public class ShuZuZhongShuZiChuXianDeCiShuIiLcof{
    public static void main(String[] args) {
         Solution solution = new ShuZuZhongShuZiChuXianDeCiShuIiLcof().new Solution();
         solution.singleNumber(new int[]{3,4,3,3});
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int singleNumber(int[] nums) {
        int n = nums.length;
        int[] bits = new int[32];
        int mask = 1;
        for (int i = 0; i < 32; i++) {
            for (int j = 0; j < n; j++) {
                if ((nums[j]& mask) != 0){
                    bits[i] = (bits[i] +1) % 3;
                }
            }
            mask <<= 1;
        }

        int result = 0;
        mask = 1;
        for (int i = 0; i < 32; i++) {
            if (bits[i] == 1){
                result += mask;
            }
            mask <<= 1;
        }
        return result;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}